/*
 * Copyright (c)  2020,  DataPipeline
 * All rights reserved.
 *
 * Id:TypeParameter.java   2020-07-18 16:25 wanglijun
 */
package cn.datacare.orm.mapping.type;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2020
 * </p>
 * <p>
 * Company/Department: DataPipeline
 * </p>
 *
 * @author wanglijun
 * @version 1.0
 * @since 2020-07-18 16:25
 */
public class TypeParameter {

    /***
     * 数据库名称
     */
    private String dialectName;
    /***
     *
     */
    private Class target;

    private ResultSet resultSet;

    private ResultSetMetaData resultSetMetaData;

    private int index;

    private String sqlId;

    /***
     *
     * @param sqlId
     * @param dialectName
     * @param target
     * @param resultSet
     * @param resultSetMetaData
     * @param index
     */
    public TypeParameter(String sqlId, String dialectName, Class target, ResultSet resultSet, ResultSetMetaData resultSetMetaData, int index) {
        super();
        this.dialectName = dialectName;
        this.target = target;
        this.resultSet = resultSet;
        this.resultSetMetaData = resultSetMetaData;
        this.index = index;
        this.sqlId = sqlId;
    }


    public boolean isPrimitive() {
        return target != null && target.isPrimitive();
    }

    public int getColumnType() throws SQLException {
        return this.resultSetMetaData.getColumnType(index);
    }

    public Object getObject() throws SQLException {
        return this.resultSet.getObject(index);
    }


    public String getDialectName() {
        return dialectName;
    }

    public void setDialectName(String dialectName) {
        this.dialectName = dialectName;
    }

    public Class getTarget() {
        return target;
    }

    public void setTarget(Class target) {
        this.target = target;
    }

    public ResultSet getResultSet() {
        return resultSet;
    }

    public void setResultSet(ResultSet resultSet) {
        this.resultSet = resultSet;
    }

    public ResultSetMetaData getResultSetMetaData() {
        return resultSetMetaData;
    }

    public void setResultSetMetaData(ResultSetMetaData resultSetMetaData) {
        this.resultSetMetaData = resultSetMetaData;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getSqlId() {
        return sqlId;
    }

    public void setSqlId(String sqlId) {
        this.sqlId = sqlId;
    }
}
